<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    // 思考题 1：
    var name = "The Window";
    var object = {
        name: "My Object",
        getNameFunc: function() {
            return function() {
                return this.name;
            };
        }
    };

    console.log(object.getNameFunc()());  // The Window
    // var f = object.getNameFunc();
    // // 类似于
    // var f = function() {
    //             return this.name;  // this 指向window
    //         };
    // f();


        
    // 思考题 2：
    var name = "The Window";
    var object = {
        name: "My Object",
        getNameFunc: function() {
            var that = this;  // this 指向的是函数的调用者
            return function() {
                return that.name;
            };
        }
    };
    console.log(object.getNameFunc()());
    // var f2 = object.getNameFunc();
    // 类似于
    // var f2 = function() {
    //             return that.name;
    //         };
    // f2();
    </script>
</body>
</html>